﻿using System;
using System.Diagnostics;
using System.Windows.Controls;
using System.Windows.Data;

namespace Flare.Pages.Hards
{
    public partial class Edit : UserControl, ITypicalPage
    {
        public string name
        {
            get { return "Редактирование"; }
        }

        int hw_id;
        DateTime createdate = new DateTime();
        public Edit(int _hw_id)
        {
            hw_id = _hw_id;
            var data = new Flare.DB.equipments().Details(hw_id);
            createdate = data.date_create;
            this.DataContext = data;
            InitializeComponent();
        }

        private void Department_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ((ObjectDataProvider)this.Resources["general_roomsDataSet"]).MethodParameters[0] = (int?)Department.SelectedValue;
        }

        private void techType_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ((ObjectDataProvider)this.Resources["equipment_marksDataSet"]).MethodParameters[0] = (int?)techType.SelectedValue;
        }

        private void techMark_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ((ObjectDataProvider)this.Resources["equipment_modelsDataSet"]).MethodParameters[0] = (int?)techMark.SelectedValue;
        }

        private void saveButton_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            var data = new DB.CeEntity.equipments();
            data.id_equipment = hw_id;
            data.id_model = (int?)techModel.SelectedValue;
            data.inventory_number = hard_ware_inventory_number.Text;
            data.factory_number = hard_ware_factory_number.Text;
            data.id_room = (int?)Room.SelectedValue;
            data.description = hard_ware_description.Text;
            data.date_create = createdate;
            try
            {
                new Flare.DB.equipments().Edit(data);
                saveButton.ShowResult();
            }
            catch (Exception ex)
            {
                glob.kernel.ShowNotice(ex.Message);
            }
        }

    }
}
